﻿
<!--<If:Maintain>-->
    <form id="FrmCreateArticle" method="post" action="{RootUrl}/_Ajax/blog.aspx?op=CreateArticle">
        <h1 class="showHiddenForm hd">添加文章</h1>
        <h1 class="hideHiddenForm hd" style="display:none">添加文章()</h1>
        <div class="hiddenForm bd">
            <input type="hidden" name="BlogId" value="{UserId}" />
            <ul>
                <li>
                    <label>CategoryId:</label><input type="text" class="CategoryId" readonly="readonly" />
                                              <input type="hidden" name="CategoryId" />
                </li>
                <li>
                    <label>Title:</label><input type="text" name="Title" class="input-field" />
                </li>
                <li>
                    <label>Content:</label><textarea name="Content" class="textarea-content" ></textarea>
                </li>
                <li>
                    <label>Summary:</label><textarea name="Summary" class="textarea-summary"></textarea>
                </li>
                <li>
                    <label>Author:</label><input type="text" name="Author" />
                </li>
                <li>
                    <label>IsOriginal:</label><select name="IsOriginal"><option value="true">是</option><option value="false">否</option></select>
                </li>
                <li>
                    <label>IsPublished:</label><select name="IsPublished"><option value="true">是</option><option value="false">否</option></select>
                </li>
                <li>
                    <label>&nbsp;</label><button>提交</button>
                </li>
            </ul>
        </div>
    </form>
    
    <div id="afterArticleCreated"><!-- 添加后数据临时显示区域 --></div>
    
<script type="text/javascript">

$(function(){

    var frm = $("#FrmCreateArticle")
    
    // 绑定分类选择事件
    var ctrl = frm.find('.CategoryId');
    var panel = $('#categoryOptionsBase').clone();
    var valField = frm.find('[name=CategoryId]');
    
    // 设定添加文章的当前分类
    panel.find('a').each( function(i,field){
        if( field.hash.replace('#','') == '<%=Request.QueryString["CategoryId"] %>'){
            ctrl.val( $(field).text() );
            valField.val( field.hash.replace('#','') );
        }
    });
    // 如果当前分类存在,则不允许再选择分类
    if( !ctrl.val() || '' == ctrl.val() ){
        var dds = new jqDropDownSelector( ctrl,panel,function(){
            panel.find('a').click(function(){
                ctrl.val($(this).text());
                valField.val( this.hash.replace('#','') );
                dds.closePanel();
            });
        });
    }
    
    // 绑定添加事件
    frm.ajaxSubmit( function(dat,fields){
        $('body').alert(dat.success||dat.failure||"");
        if( dat.success ){
            if( fields.Title ){ 
                $('#afterArticleCreated').prepend( '<p><a href="ArticleDetail.aspx?ArticleId='+dat.ArticleId+ '">' +fields.Title + '</a></p>' );
            }
        }
    });
});

</script>
<!--</If:Maintain>-->
